package com.harmontronics.hanma.paas.paas.domain.app.repository.persistence;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.consts.NumberEnum;
import com.harmontronics.hanma.paas.paas.domain.app.repository.mapper.HmProcInstReadMapper;
import com.harmontronics.hanma.paas.paas.domain.app.repository.po.HmProcInstReadPO;
import com.harmontronics.hanma.paas.paas.domain.app.entity.valueobject.Fields;
import org.springframework.stereotype.Repository;


/**
 * @author ldb
 */
@Repository("hmProcInstReadRepository")
public class HmProcInstReadRepository extends ServiceImpl<HmProcInstReadMapper, HmProcInstReadPO> {

    public IPage<HmProcInstReadPO> selectPage(QueryWrapper<HmProcInstReadPO> queryWrapper, Page<HmProcInstReadPO> page) {
        return baseMapper.selectPage(page, queryWrapper);
    }


    public boolean exists(String procInstId,String userId,String taskId){
        QueryWrapper<HmProcInstReadPO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq(Fields.PROC_INST_ID,procInstId);
        queryWrapper.eq(Fields.USER_ID,userId);
        queryWrapper.eq(Fields.TASK_ID,taskId);
        return baseMapper.selectCount(queryWrapper) >0;
    }

    public void read(String taskId,String userId){
        UpdateWrapper<HmProcInstReadPO> updateWrapper=new UpdateWrapper<>();
        updateWrapper.eq(Fields.USER_ID,userId);
        updateWrapper.eq(Fields.TASK_ID,taskId);
        updateWrapper.set(Fields.READ, NumberEnum.ONE.getNum());
        baseMapper.update(null,updateWrapper);
    }


}